﻿<span style='font-size:11px; color:#000000; background:#ffffff; '><pre>
<span style='color:#800000; font-weight:bold; '>protected</span> <span style='color:#800000; font-weight:bold; '>void</span> createPdfButton_Click<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>object</span> sender<span style='color:#808030; '>,</span> EventArgs e<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#696969; '>// Create a PDF document</span>
    Document pdfDocument <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> Document<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set license key received after purchase to use the converter in licensed mode</span>
    <span style='color:#696969; '>// Leave it not set to use the converter in demo mode</span>
    pdfDocument<span style='color:#808030; '>.</span>LicenseKey <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>fvDh8eDx4fHg4P/h8eLg/+Dj/+jo6Og=</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Display the bookmarks panel when the PDF document is opened in a PDF viewer</span>
    pdfDocument<span style='color:#808030; '>.</span>ViewerPreferences<span style='color:#808030; '>.</span>PageMode <span style='color:#808030; '>=</span> ViewerPageMode<span style='color:#808030; '>.</span>UseOutlines<span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>try</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// The titles font used to mark various sections of the PDF document</span>
        PdfFont titleFont <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddFont<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>new</span> Font<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Times New Roman</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>12</span><span style='color:#808030; '>,</span> FontStyle<span style='color:#808030; '>.</span>Regular<span style='color:#808030; '>,</span> GraphicsUnit<span style='color:#808030; '>.</span>Point<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a new PDF page to PDF document</span>
        PdfPage page1 <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        TextElement pageText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page 1. Destination of a Top Bookmark with Fit Width View Mode.</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> titleFont<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page1<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>pageText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a new PDF page to PDF document</span>
        PdfPage page2 <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        pageText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page 2. Destination of a Top Bookmark with Custom Zoom Level.</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> titleFont<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page2<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>pageText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a new PDF page to PDF document</span>
        PdfPage page3 <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        pageText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page 3. Destination of a Child Bookmark with Fit Width and Height View Mode.</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> titleFont<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page3<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>pageText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a new PDF page to PDF document</span>
        PdfPage page4 <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        pageText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> page4<span style='color:#808030; '>.</span>PageSize<span style='color:#808030; '>.</span>Height <span style='color:#808030; '>/</span> <span style='color:#008c00; '>2</span> <span style='color:#808030; '>-</span> <span style='color:#008c00; '>20</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page 4. Destination of a Top Bookmark for the Middle of the Page.</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> titleFont<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page4<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>pageText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a new PDF page to PDF document</span>
        PdfPage page5 <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        pageText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page 5. Destination of a Child Bookmark with Colored Title.</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> titleFont<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page5<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>pageText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a new PDF page to PDF document</span>
        PdfPage page6 <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        pageText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page 6. Destination of a Child Bookmark with Italic Style Title.</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> titleFont<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page6<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>pageText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a top level bookmark for first page setting destination view mode to fit viewer window horizontally</span>
        ExplicitDestination page1Destination <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> ExplicitDestination<span style='color:#808030; '>(</span>page1<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>new</span> PointF<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> DestinationViewMode<span style='color:#808030; '>.</span>FitH<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        Bookmark page1TopBookmark <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Bookmarks<span style='color:#808030; '>.</span>AddNewBookmark<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Top Bookmark with Fit Width View Mode</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> page1Destination<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page1TopBookmark<span style='color:#808030; '>.</span>Style <span style='color:#808030; '>=</span> PdfBookmarkStyle<span style='color:#808030; '>.</span>Bold<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a top level bookmark for second page setting the zoom level to 125%</span>
        ExplicitDestination page2Destination <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> ExplicitDestination<span style='color:#808030; '>(</span>page2<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>new</span> PointF<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> DestinationViewMode<span style='color:#808030; '>.</span>XYZ<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page2Destination<span style='color:#808030; '>.</span>ZoomPercentage <span style='color:#808030; '>=</span> <span style='color:#008c00; '>125</span><span style='color:#800080; '>;</span>
        Bookmark page2TopBookmark <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Bookmarks<span style='color:#808030; '>.</span>AddNewBookmark<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Top Bookmark with Custom Zoom Level</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> page2Destination<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page2TopBookmark<span style='color:#808030; '>.</span>Style <span style='color:#808030; '>=</span> PdfBookmarkStyle<span style='color:#808030; '>.</span>Normal<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a child bookmark for third page setting destination view mode to fit viewer window horizontally and vertically</span>
        ExplicitDestination page3Destination <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> ExplicitDestination<span style='color:#808030; '>(</span>page3<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>new</span> PointF<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> DestinationViewMode<span style='color:#808030; '>.</span>Fit<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        Bookmark page3ChildBookmark <span style='color:#808030; '>=</span> page2TopBookmark<span style='color:#808030; '>.</span>DescendantBookmarks<span style='color:#808030; '>.</span>AddNewBookmark<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Child Bookmark with Fit Width and Height View Mode</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> page3Destination<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a top level bookmark for fourth page with destination point in the middle of the PDF page </span>
        ExplicitDestination page4Destination <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> ExplicitDestination<span style='color:#808030; '>(</span>page4<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>new</span> PointF<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> page4<span style='color:#808030; '>.</span>PageSize<span style='color:#808030; '>.</span>Height <span style='color:#808030; '>/</span> <span style='color:#008c00; '>2</span> <span style='color:#808030; '>-</span> <span style='color:#008c00; '>20</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        Bookmark page4TopBookmark <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Bookmarks<span style='color:#808030; '>.</span>AddNewBookmark<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Top Bookmark for the Middle of the Page</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> page4Destination<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page4TopBookmark<span style='color:#808030; '>.</span>Style <span style='color:#808030; '>=</span> PdfBookmarkStyle<span style='color:#808030; '>.</span>Bold<span style='color:#800080; '>;</span>
        page4TopBookmark<span style='color:#808030; '>.</span>Color <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Blue<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a child bookmark with colored text</span>
        ExplicitDestination page5Destination <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> ExplicitDestination<span style='color:#808030; '>(</span>page5<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>new</span> PointF<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        Bookmark page5ChildBookmark <span style='color:#808030; '>=</span> page4TopBookmark<span style='color:#808030; '>.</span>DescendantBookmarks<span style='color:#808030; '>.</span>AddNewBookmark<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Child Bookmark with Colored Title</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> page5Destination<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page5ChildBookmark<span style='color:#808030; '>.</span>Color <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Red<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a child bookmark with italic style text</span>
        ExplicitDestination page6Destination <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> ExplicitDestination<span style='color:#808030; '>(</span>page6<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>new</span> PointF<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        Bookmark page6ChildBookmark <span style='color:#808030; '>=</span> page4TopBookmark<span style='color:#808030; '>.</span>DescendantBookmarks<span style='color:#808030; '>.</span>AddNewBookmark<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Child Bookmark with Italic Colored Title</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> page6Destination<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        page6ChildBookmark<span style='color:#808030; '>.</span>Style <span style='color:#808030; '>=</span> PdfBookmarkStyle<span style='color:#808030; '>.</span>Italic<span style='color:#800080; '>;</span>
        page6ChildBookmark<span style='color:#808030; '>.</span>Color <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Green<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Save the PDF document in a memory buffer</span>
        <span style='color:#800000; font-weight:bold; '>byte</span><span style='color:#808030; '>[</span><span style='color:#808030; '>]</span> outPdfBuffer <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Save<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Send the PDF as response to browser</span>

        <span style='color:#696969; '>// Set response content type</span>
        Response<span style='color:#808030; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Content-Type</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>application/pdf</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Instruct the browser to open the PDF file as an attachment or inline</span>
        Response<span style='color:#808030; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Content-Disposition</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>attachment; filename=Bookmarks.pdf; size={0}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> outPdfBuffer<span style='color:#808030; '>.</span>Length<span style='color:#808030; '>.</span>ToString<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Write the PDF document buffer to HTTP response</span>
        Response<span style='color:#808030; '>.</span>BinaryWrite<span style='color:#808030; '>(</span>outPdfBuffer<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// End the HTTP response and stop the current page processing</span>
        Response<span style='color:#808030; '>.</span>End<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#800000; font-weight:bold; '>finally</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// Close the PDF document</span>
        pdfDocument<span style='color:#808030; '>.</span>Close<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>
</pre>
</span>